package factory;

import dal.Configuracion;
import dao.ColumnaDao;
import dao.mysql.ColumnaDaoMySQL;
import dao.TablaDao;
import dao.mysql.TablaDaoMySQL;
import dto.Columna;
import dto.Tabla;
import java.util.Iterator;
import java.util.Vector;

/**
 *
 * @author Jose Carlos Gutierrez
 */
public class FactoryDaoMySQL extends FactoryDao{

    private FactoryDaoMySQL(){
        ;
    }

    public static FactoryDao getFactoryInstance(){
        if(instancia==null)
            instancia = new FactoryDaoMySQL();
        return instancia;
    }

    @Override
    public TablaDao getNewTablaDao() {
        return new TablaDaoMySQL();
    }

    @Override
    public ColumnaDao getNewColumnaDao() {
        return new ColumnaDaoMySQL();
    }

    public static void main(String[] args){

        Configuracion config = Configuracion.getConfiguracion();
        config.setDbEngine("MySQL");
        config.setDbHost("localhost");
        config.setDbInstace("");
        config.setDbUser("root");
        config.setDbName("base");
        config.setDbPort("3306");
        config.setDbPassword("root");

        TablaDao dao = FactoryDao.getFactoryInstance().getNewTablaDao();
        Vector<Tabla> v = dao.selectTodos();
        Iterator<Tabla> i = v.iterator();
        while(i.hasNext()){
            Tabla objTabla = i.next();
            ColumnaDao obj = FactoryDao.getFactoryInstance().getNewColumnaDao();
            objTabla.setColumnas(obj.select(objTabla.getNombreTabla()));

            Iterator<Columna> it = objTabla.getColumnas().iterator();
            while(it.hasNext()){
                System.out.println(it.next());
            }
        }
    }


}
